<?php
require "config.php";
require "database.php";
require "hash_functions.php";
require "link_functions.php";

//--------------------actual site code----------------------------------------//

$show_link = false;

if (isset($_REQUEST['id'])) { //Checsk to see if this is a view
    $link = get_link($_REQUEST['id'], $CONF['database_name'], $CONF['server'], $CONF['user_name'], $CONF['pass_word']);
    if (!$link) {
        header("Location: http://" . $_SERVER['HTTP_HOST'] .
                dirname($_SERVER['PHP_SELF']));
        exit;
    } else {
        header("Location: " . $link);
        exit;
    }
}

if (isset($_POST['link'])) {
    $key = submit($_POST['link'], $CONF['database_name'], $CONF['server'], $CONF['user_name'], $CONF['pass_word']);
    $show_link = true;
    if (!$key) {
        header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']));
        exit;
    }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Shrinker</title>
        <style type='text/css'>
            a {color:#88aa00; font-family: sans-serif}
            a.marked {color:#ff6600;}
            a {text-decoration: none;}
            a:hover {text-decoration: underline;}
            a:visited {text-decoration: none;}
            a.div { color:#000; }
            body {font-family: sans-serif; font-size: 12px; padding: 50px 20px 0px 20px;background-color:white;}
            div.top {position: absolute; top: 0px; left: 0px;background-color: #eee; width: 100%; border-bottom: 1px solid #ccc;text-align:right; }
            div.menu {display: block; padding: 5px; margin: 0px;}
            div.footer {clear: both; width: 95%; text-align: center; padding: 0px; margin: 0px; position: absolute; bottom: 0px;}
            div.results { padding:5px;border-bottom: 1px solid #F00; color:#000; }
            span.name { color:#F00; }
            span.size { color:#00F; }
            #main img {border: none; margin: 0px;}
            #main {width: 100%; text-align: center; margin-top: 0%; padding-top: 30px;}
            #main fieldset{border: none;}

        </style>
    </head>
    <body>
        <div class=top>
            <div class=menu>
                <a href='#'>Home</a> | 
                <a href='#'>Link Checker</a> | 
                <a href='#'>Statistic</a> | 
                <a href='#'>About</a>
            </div>
        </div>

        <div id=main>
            <img src='http://shrinker.tk/fxxruw.jpg' />
            <?php
            $submit_form = <<<END
            <form action='index.php' method='post'>
                <b>A Link Shortening Service</b><br />
                <input style='width:300px' 
                       type='text' 
                       name='link'>
                <input type='submit' value='submit'>
            </form>
END;
            if ($show_link) {
                print "<br /><input style='width:300px' 
                       type='text'
                       value='http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/l/" . $key . "' 
                       name='link'>";
            } else {
                print $submit_form;
            }
            ?>

        </div>

        <div class=footer>This site is not responsible for links! Usage of this Service is Free!</div>

    </body>
</html>
